<template>
  <div>
    <h2>侦听器</h2>
    <input type="text" v-model.lazy="uname">
    <span>{{msg}}</span>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data() {
    return {
      uname: 'zhangsan',
      msg: ''
    }
  },
  watch: {
    // 函数写法
    async uname(val){
      // console.log(newVal,oldVal)
      if(val ===''){
        this.msg = ''
        return
      }
      const {data: res} = await axios.get('http://www.itcbc.com:3006/api/finduser/'+ val)
      this.msg = res.message
    }
   
  }
}
</script>
